var netcore = require('../../../utils/network.js')
var tripleDes = require('../../../utils/CKCrypto.js')
var comm=require('../../../utils/comm_util.js')
//分销列表
function getDistributionList(pageIndex, orderType,teacherId, callBack){
  var map=new Map()
  map.set("currentPage", pageIndex);
  map.set("pageSize", "10");
  map.set("order", orderType);
  if(teacherId!=''){
  map.set("teacherId", teacherId);
  }
  console.log(map)
  netcore.requestPost("activies/getNormalDistributions.do", map, function (success) {
    success.forEach(function(item,index){
      item.coursePrice = item.coursePrice.toFixed(2)
    })
    callBack(success)
  }, function (code, errMsg) {
    wx.showToast({
      title: errMsg,
      duration: 3000
    })
  })
}
//获取参与分销人列表
function getDistributionPersion(distributId,pageIndex,callBack){
  var map = new Map()
  map.set("distributId", distributId)
  map.set("currentPage", pageIndex);
  map.set("pageSize", "10");
  netcore.requestPost("activies/getDistributionsPer.do", map, function (success) {
    success.forEach(function(item,index){
      item.inTime = comm.formatDateInDay(item.inTime)
    })
    callBack(success)
  }, function (code, errMsg) {
    wx.showToast({
      title: errMsg,
      duration: 3000
    })
  })
}
//生成代理链接
function generateDistributions(mId, courseNo,callBack){
  var map = new Map()
  map.set("mId", tripleDes.enCode(mId))
  map.set("courseNo", tripleDes.enCode(courseNo));
  netcore.requestPost("activies/generateDistributions.do", map, function (success) {
    callBack(1,success)
  }, function (code, errMsg) {
    callBack(-1, errMsg)
  })
}
function getMyDistributions(pageIndex,callBack){
  var map = new Map()
  map.set("currentPage", pageIndex);
  map.set("pageSize", "10");
  netcore.requestPost("activies/getMyDistributions.do", map, function (success) {
    success.list.forEach(function(item,index){
      item.indate = comm.formatDateInDay(item.indate)
    })
    callBack(success)
  }, function (code, errMsg) {
    wx.showToast({
      title: errMsg,
      duration: 3000
    })
  })
}
module.exports = {
  getDistributionList: getDistributionList,
  getDistributionPersion: getDistributionPersion,
  generateDistributions: generateDistributions,
  getMyDistributions: getMyDistributions
}